// $Id: daemon.h 86 2011-05-04 17:33:43Z cedric.shih@gmail.com $
/*
 * Copyright 2011 Cedric Shih (cedric dot shih at gmail dot com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef HTTPD_INTERNAL_H_
#define HTTPD_INTERNAL_H_

#include <nio/channel.h>
#include <nio/server.h>

#include "niohttpd.h"

struct niohttpd {
	struct nioreactor *reactor;
	struct nioserver *server;
	struct niohttpd_handlers *handlers;
	struct niohttpd_streams *streams;
	int dump;
};

struct niohttpd_handler_entry *niohttpd_match_handler(
		struct niohttpd *server, const char *uri);

void niohttpd_remove_handler(struct niohttpd *server,
		struct niohttpd_handler_entry *handler);

struct niohttpd_stream_entry *niohttpd_match_stream(
		struct niohttpd *server, const char *uri);

int niohttpd_add_stream_client(struct niohttpd *server, const char *uri,
		struct niochannel *channel);

void niohttpd_remove_stream(struct niohttpd *server,
		struct niohttpd_stream_entry *stream);

void niohttpd_remove_stream_client(struct niohttpd *server,
		struct niohttpd_client *client, int notify);

struct niobuffer_factory niohttpd_buffer_factory;

struct niochannel_factory niohttpd_channel_factory;

struct niobuffer *niohttpd_buffer_create(struct niochannel *channel, void *arg);

void niohttpd_buffer_release(struct niobuffer *buffer, void *arg);

struct niochannel *niohttpd_channel_create(struct niosocket *socket, void *arg);

void niohttpd_channel_release(struct niochannel *channel, void *arg);

#endif /* HTTPD_INTERNAL_H_ */
